import com.mongodb.BasicDBObject;
import com.mongodb.MongoClient;
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.model.UpdateOptions;
import org.bson.Document;

public class 非经常性损益合并 {
    public static void main(String[] args) {
        MongoCollection<Document> sourse = new MongoClient("192.168.1.175", 27017)
                .getDatabase("NFSD").getCollection("非经常性损益");
        MongoCollection<Document> target = new MongoClient("192.168.1.175", 27017)
                .getDatabase("NFSD").getCollection("非经常性损益_合并");
        FindIterable<Document> documents = sourse.find();
        documents.noCursorTimeout(true);
//        HashMap<String, TermModel> hm1 = GetTermsIDF();
        int count = 1;
//        HashSet<String> stopWords = GetStopWords();
        for (Document document : documents) {
//            System.out.println(document);
            String code = document.getString("code").replace(".SZ","").replace(".SH","");;
            String time = document.getString("报告期").replace("中报","-06-31").replace("年报","-12-31");
            Document doc = new Document("_id",code+"_"+time);
//            System.out.println(doc);
            doc.append(document.getString("指标"),document.get("value"));
            System.out.println(doc);
            target.updateOne(new BasicDBObject("_id", doc.getString("_id")), new BasicDBObject("$set", doc), (new UpdateOptions()).upsert(true));
//            System.out.println(document);
        }
    }
}
